package com.hanzidong.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * 自定义拦截器
 * @author 
 * @version
 */
public class MyInterceptor extends HandlerInterceptorAdapter{

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		
		//获取session中的登录对象
		Object object = request.getSession().getAttribute("LOGIN_USER");
		
		
		if(object == null) {
			//判断，如果为空，则跳转到登录页面，否则，直接放行
			
			//响应重定向
			response.sendRedirect("/user/toLogin");
			
			return false;
		}else {
			return true;
		}
	}

	
	
}
